#include "Element.h"

N2F::Iw3D::Element::Element(const N2F::Iw3D::ScaleFactor &scaleFactor)
	: scaleFactor(scaleFactor)
{
	this->pos = CIwFVec2(0.0f, 0.0f);
	this->size = CIwFVec2(0.0f, 0.0f);
	this->isActive = false;
	this->isVisible = false;

	this->originPoint = PointOriginTopLeft;
	this->scaleGroup = ScaleGroupRelative;

	return;
}

N2F::Iw3D::Element::~Element()
{
	return;
}

const N2F::Iw3D::ScaleFactor N2F::Iw3D::Element::getScaleFactor() const
{
	return(this->scaleFactor);
}

void N2F::Iw3D::Element::setScaleFactor(const ScaleFactor &scaleFactor)
{
	this->scaleFactor = scaleFactor;

	return;
}

const N2FScaleGroup N2F::Iw3D::Element::getScaleGroup() const
{
	return(this->scaleGroup);
}

void N2F::Iw3D::Element::setScaleGroup(N2FScaleGroup group)
{
	this->scaleGroup = group;

	return;
}

const N2FOriginPoint N2F::Iw3D::Element::getOriginPoint() const
{
	return(this->originPoint);
}

void N2F::Iw3D::Element::setOriginPoint(N2FOriginPoint originPoint)
{
	this->originPoint = originPoint;

	return;
}

void N2F::Iw3D::Element::setPositioningMetrics(N2FScaleGroup group, N2FOriginPoint point)
{
	this->scaleGroup = group;
	this->originPoint = point;

	return;
}

const CIwFVec2 N2F::Iw3D::Element::getPosition() const
{
	return(this->pos);
}

void N2F::Iw3D::Element::setPosition(CIwFVec2 pos)
{
	this->pos.x = pos.x;
	this->pos.y = pos.y;

	return;
}

void N2F::Iw3D::Element::setPosition(float x, float y)
{
	this->pos.x = x;
	this->pos.y = y;

	return;
}

const CIwFVec2 N2F::Iw3D::Element::getSize() const
{
	return(this->size);
}

void N2F::Iw3D::Element::setSize(CIwFVec2 size)
{
	this->size = size;

	return;
}

const bool N2F::Iw3D::Element::getVisible() const
{
	return(this->isVisible);
}

void N2F::Iw3D::Element::setVisible(bool isVisible)
{
	this->isVisible = isVisible;

	return;
}

const bool N2F::Iw3D::Element::getActive() const
{
	return(this->isActive);
}

void N2F::Iw3D::Element::setActive(bool isActive)
{
	this->isActive = isActive;

	return;
}

void N2F::Iw3D::Element::kill()
{
	this->OnKill();

	return;
}

void N2F::Iw3D::Element::move(float x, float y)
{
	this->pos.x += x;
	this->pos.y += y;

	return;
}

void N2F::Iw3D::Element::move(CIwFVec2 move)
{
	this->pos += move;

	return;
}

void N2F::Iw3D::Element::OnKill()
{
	return;
}

void N2F::Iw3D::Element::OnTouch(N2F::Iw3D::InputPoint point)
{
	return;
}

void N2F::Iw3D::Element::OnKey(N2F::Iw3D::InputKey key)
{
	return;
}

CIwFVec2 N2F::Iw3D::Element::translateSize()
{
	CIwFVec2 ret;
	ret.x = this->size.x * this->scaleFactor.scale;
	ret.y = this->size.y * this->scaleFactor.scale;

	return(ret);
}

CIwFVec2 N2F::Iw3D::Element::translateSize(float scale)
{
	CIwFVec2 ret;
	ret.x = this->size.x * scale;
	ret.y = this->size.y * scale;

	return(ret);
}

CIwFVec2 N2F::Iw3D::Element::translatePosition()
{
	return(this->translateVector(this->pos, this->size, this->originPoint, this->scaleGroup));
}

CIwFVec2 N2F::Iw3D::Element::translatePosition(float scale)
{
	return(this->translateVector(this->pos, this->size, scale, this->originPoint, this->scaleGroup));
}

CIwFVec2 N2F::Iw3D::Element::translateVector(CIwFVec2 v, CIwFVec2 s, N2FOriginPoint o, N2FScaleGroup g)
{
	return(this->translateVector(v, s, this->scaleFactor.scale, o, g));
}

CIwFVec2 N2F::Iw3D::Element::translateVector(CIwFVec2 vector, CIwFVec2 size, float scale, N2FOriginPoint opoint, N2FScaleGroup group)
{
	CIwFVec2 ret = CIwFVec2(0.0f, 0.0f);
	CIwFVec2 origin = CIwFVec2(0.0f, 0.0f);
	CIwFVec2 ssize = CIwFVec2(size.x * scale, size.y * scale);

	switch (opoint)
	{
	case PointOriginTopLeft:
		origin.x = 0.0f;
		origin.y = 0.0f;

		break;
	case PointOriginTopCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = 0.0f;

		break;
	case PointOriginTopRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = 0.0f;

		break;
	case PointOriginMidLeft:
		origin.x = 0.0f;
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginMidCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginMidRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginBotLeft:
		origin.x = 0.0f;
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	case PointOriginBotCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	case PointOriginBotRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	}

	switch (group)
	{
	case ScaleGroupAbsolute:
		ret.x = (vector.x * scale) + this->scaleFactor.offset.x + origin.x;
		ret.y = (vector.y * scale) + this->scaleFactor.offset.y + origin.y;

		break;
	case ScaleGroupRelative:
		ret.x = (vector.x * scale) + origin.x;
		ret.y = (vector.y * scale) + origin.y;

		break;
	}

	return(ret);
}

CIwFVec2 N2F::Iw3D::Element::unTranslateVector(CIwFVec2 vector, CIwFVec2 size, float scale, N2FOriginPoint opoint, N2FScaleGroup group)
{
	CIwFVec2 ret = CIwFVec2(0.0f, 0.0f);
	CIwFVec2 origin = CIwFVec2(0.0f, 0.0f);
	CIwFVec2 ssize = CIwFVec2(size.x * scale, size.y * scale);

	switch (opoint)
	{
	case PointOriginTopLeft:
		origin.x = 0.0f;
		origin.y = 0.0f;

		break;
	case PointOriginTopCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = 0.0f;

		break;
	case PointOriginTopRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = 0.0f;

		break;
	case PointOriginMidLeft:
		origin.x = 0.0f;
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginMidCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginMidRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = (IwGxGetScreenHeight() / 2.0f) - (ssize.y / 2.0f);

		break;
	case PointOriginBotLeft:
		origin.x = 0.0f;
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	case PointOriginBotCenter:
		origin.x = (IwGxGetScreenWidth() / 2.0f) - (ssize.x / 2.0f);
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	case PointOriginBotRight:
		origin.x = IwGxGetScreenWidth() - ssize.x;
		origin.y = IwGxGetScreenHeight() - ssize.y;

		break;
	}

	switch (group)
	{
	case ScaleGroupAbsolute:
		ret.x = (vector.x - (this->scaleFactor.offset.x + origin.x)) / scale;
		ret.y = (vector.y - (this->scaleFactor.offset.y + origin.y)) / scale;

		break;
	case ScaleGroupRelative:
		ret.x = (vector.x - origin.x) / scale;
		ret.y = (vector.y - origin.y) / scale;

		break;
	}

	return(ret);
}

